function [error_train, error_val] = learningCurve(X, y, Xval, yval, lambda)
    m = size(X, 1);

    for i = 1:m
        theta = trainLinearReg(X(1:i, :), y(1:i), lambda);
        error_train(i) = linearRegCostFunction(theta, X(1:i, :), y(1:i), 0);
        error_val(i) = linearRegCostFunction(theta, Xval, yval, 0);
    end

end
